package com.gomore.opple.module.cards.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.gomore.opple.R;
import com.gomore.opple.common.GlobalConstant;
import com.gomore.opple.utils.DensityUtil;
import com.gomore.opple.web.cgform.jdecard.entity.TOJingdongEcardEntity;
import com.gomore.opple.widgets.adapter.CommonAdapter;
import com.gomore.opple.widgets.adapter.ViewHolder;

import java.util.List;

/**
 * Created by asus on 2017/5/31.
 */
public class PagerAdapter extends CommonAdapter<TOJingdongEcardEntity> {
    private Activity mactivity;
    private Context mContext;
    private int width;

    public PagerAdapter(Activity activity, Context context, int layoutId, List<TOJingdongEcardEntity> messageList) {
        super(context, layoutId, messageList);
        mactivity = activity;
        mContext = context;
        width = DensityUtil.screenWith(context) - DensityUtil.dpToPx(mContext, 40);
    }

    @Override
    protected void convert(ViewHolder holder, TOJingdongEcardEntity toJingdongEcardEntity, int position) {
        ImageView jd_card = holder.getView(R.id.jd_card);
        RelativeLayout invisible_linear = holder.getView(R.id.invisible_linear);
        TextView card_number = holder.getView(R.id.card_number);
        TextView password = holder.getView(R.id.password);
        if (GlobalConstant.JDCard.isNewCard(toJingdongEcardEntity.getDenomation())) {
            int jd_card_height = width * 290 / 620;
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(width, jd_card_height);
            jd_card.setLayoutParams(layoutParams);
            jd_card.setBackgroundResource(GlobalConstant.JDCard.getCardByMoney(toJingdongEcardEntity.getDenomation()));
            invisible_linear.setVisibility(View.GONE);
        } else {
            int jd_card_height = width * 173 / 620;
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(width, jd_card_height);
            jd_card.setLayoutParams(layoutParams);
            jd_card.setBackgroundResource(GlobalConstant.JDCard.getHalfCardByMoney(toJingdongEcardEntity.getDenomation()));

            invisible_linear.setVisibility(View.GONE);
            int scratch_height = width * 124 / 620;
            LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(width, scratch_height);
            invisible_linear.setLayoutParams(layoutParams1);
            card_number.setText("卡号  " + toJingdongEcardEntity.getCardNumber());
            password.setText("密码  " + toJingdongEcardEntity.getCardPassword());
        }
    }
}
